import { defineConfig } from "vite";
import vue from "@vitejs/plugin-vue";
import { join, resolve } from "path";
import AutoImport from "unplugin-auto-import/vite";
import Components from "unplugin-vue-components/vite";
import { ElementPlusResolver } from "unplugin-vue-components/resolvers";
import { createSvgIconsPlugin } from "vite-plugin-svg-icons";

export default defineConfig({
   plugins: [
      vue(),
      /*ElementPlus组件库组件的按需导入*/
      AutoImport({
         resolvers: [
            ElementPlusResolver(),
         ],
      }),
      Components({
         resolvers: [
            ElementPlusResolver(),
         ],
      }),
      createSvgIconsPlugin({
         // 指定要缓存的图标文件夹
         iconDirs: [resolve(process.cwd(), "src/assets/icons")],
         // 指定symbolId格式
         symbolId: "icon-[dir]-[name]",
      }),
   ],
   resolve: {
      /*路径别名*/
      alias: {
         "@": join(__dirname, "src"),
      },
   },
   /*css配置选项*/
   css: {
      preprocessorOptions: {
         // less的自动化导入
         less: {
            javascriptEnabled: true,
            additionalData: "@import \"./src/styles/variables.less\"; @import \"./src/styles/mixins.less\";",
         },
      },
   },
   // 开启IP域名访问
   server: {
      host: "0.0.0.0",
      port: 8080,
      open: true,
   },
});
